<template>
<div>
	<!-- <div class="g_top_box">
		<div class="g_right_box">
			<Button @click="download" style="margin-right:20px;">下载案例</Button>
			<Button type="primary" @click="import_data">导入数据</Button>
			
		</div> 
		<div class="g_left_box"><h4>银行记账列表</h4></div>
	</div> -->
	<content_top title="币种列表"></content_top>
	
	<div class="g_box">
		<div class="g_head">
			<h3>数据列表</h3>
			<div class="g_box_right">
				<ButtonGroup class="g_act_box">
					<Button @click="handleAddBz">添加</Button>
				</ButtonGroup>
			</div>
		</div>
		<div class="g_box_con">
			<Table :loading="loading" :columns="Columns" :data="list" style="width: 100%;" size="small" :border="true" ref="table">
				<div slot="footer" style="border-top: 1px solid #eee;padding: 0 10px; text-align: right;    font-size: 14px;">
					<div style="float:left;">
						<Button @click="batch_del">批量删除</Button>
					</div>
					<div style="float:right;">
						<Page :total="count" show-elevator show-total @on-change="goto_page" />
					</div>
				</div>
			</Table>
		</div>
	</div>
<!-- 编辑币种 -->
	<Modal
        v-model="einfo.show"
        title="编辑币种"
        >
		<Form :model="einfo.info" :label-width="150" style="width: 100%" :rules="ruleValidate">
			
			<FormItem label="币种名称：" prop="month">
				<Input v-model="einfo.info.name" placeholder="" style="width: 240px;"></Input>
			</FormItem>
			<FormItem label="当前汇率：" prop="month">
				<Input v-model="einfo.info.exchange_rate" placeholder="" style="width: 240px;"></Input>
			</FormItem>
			<FormItem label="符号：">
				<Input v-model="einfo.info.mark" placeholder="" style="width: 240px;"></Input>
			</FormItem>
		</Form>

		<div slot="footer" style="text-align: center;">
			<Button type="success" size="large" @click="einfo_ok">提交</Button>
		</div>
	</Modal>
	<!-- 表格 -->
	<info_box v-model="history.show" :name="history.name"></info_box>

</div>
</template>

<script>
import content_top from '@/themes/components/content_top';
import info_box from './info';

export default {
    name: 'system_list',
    data () {
		let self = this;
        return {
			single: false,
			einfo:{
				show: false,
				name:'',
				info:{
					name:'',
					exchange_rate:'',
					mark:''
				}
			},
			history:{
				show: false,
				id:0,
			},
            Columns: [
				{
					type: 'selection',
					width: 80,
					align: 'center'
				},
				{
					title: '币种名称',
					key: 'name',
					align: 'center',
                    width: 150,
                },
				{
                    title: '符号',
					key: 'mark',
					width: 100,
					align: 'center'
                },
				{
                    title: '当前汇率',
					key: 'exchange_rate',
					width: 150,
					align: 'center'
                },
				{
                    title: '更新日期',
					key: 'addtime',
					width: 150,
					align: 'center'
                },
				{
                    title: '更新来源',
					key: 'source',
					width: 200,
					align: 'center'
                },
				{
					title:'操作',
					key: 'action',
					align: 'center',
					render: (h, params) => {
						return h('div', [
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										this.dbedit(params.row,params.row.id)
									}
								}
							}, '编辑'),
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									marginRight: '5px',
								},
								on: {
									click: () => {
										self.show_history(params.row.name);
									}
								}
							}, '历史记录'),
							h('Button', {
								props: {
									type: 'info',
									size: 'small',
								},
								style: {
									
								},
								on: {
									click: () => {
										self.remove(params.row.id)
									}
								}
							}, '删除')
						]);
					}
				}
            ],
            list:[],
			page:1,
			count:0,
			loading:false,
			filter:{
				
			},
			ruleValidate:{
				name:[
					{ required: true, message: '请输入币种名称', trigger: 'blur' }
				],
				exchange_rate:[
					{ required: true, message: '请输入汇率', trigger: 'blur' }
				]
			},
        };
	},
	components:{
		content_top,
		info_box,
	},
	created(){
		this.load_data();
	},
    computed: {
       
    },
	methods:{
		load_data(){
			var self = this;
			var postdata = {
				f:this.filter,
				page:this.page
			};
			Whttp.load('User/Currency/get_newList',postdata,function(result){
				self.list = result;
				self.count = result.length;
			})
		},
		qurey(){
			this.page = 1;
			this.load_data();
		},
		dbedit(row,index){
			this.einfo.info = this._getData(row);
			this.einfo.id = row.id;
			this.einfo.show = true;
		},
		handleAddBz(){
			this.einfo.show = true;
			this.einfo.id = 0;
			this.einfo.info = {};
		},
		remove(id){
			var self = this;
			if(!confirm('是否删除')){
				return false;
			}
			var postdata = {
				id:id
			};
			Whttp.load('User/Currency/del',postdata,function(result){
				self.load_data();
				self.$Message.info('删除成功');
			});
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		batch_del(){
			var ids = [];

			if(!confirm('是否批量删除')){
				return false;
			}
			
			
			var sels = this.$refs['table'].getSelection();
			
			for(var i=0;i<sels.length;i++){
				ids.push(sels[i].id);
			}
			
			var self = this;
			var postdata = {
				ids:ids,
			};
			Whttp.load('User/Currency/batch_del',postdata,function(result){
				self.load_data();
				self.$Message.info('操作成功');
			});
			
			
		},
		einfo_ok(){
		
			var self = this;
			var postdata = {
				name:this.einfo.info.name,
				exchange_rate:this.einfo.info.exchange_rate,
				mark:this.einfo.info.mark
			};
			Whttp.load('User/Currency/save',postdata,function(result){
				self.load_data();
				self.$Message.info('操作成功');
				self.einfo.show =false;
			});
			
		},
		show_history(name){
			this.history.name = name;
			this.history.show = true;
		}
	}
};
</script>
<style scoped>

</style>